package org.zeurox.dao;

import java.util.List;


import org.hibernate.SessionFactory;
import org.zeurox.model.Login;

public class UserDAO implements IUserDAO {

	private SessionFactory sessionFactory;

	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public void addUser(Login user) {
		getSessionFactory().getCurrentSession().save(user);
	}
	
	@Override
	public void deleteUser(Login user) {
		getSessionFactory().getCurrentSession().delete(user);
	}

	@Override
	public Login getUserById(int id) {
		List list = getSessionFactory().getCurrentSession()
					.createQuery("from Login where id=?")
					.setParameter(0, id).list();
		return (Login)list.get(0);
	}
	
	@Override
	public List<Login> getUsers() {
		List list = getSessionFactory().getCurrentSession().createQuery("from Login").list();
		return list;
	}

	@Override
	public void updateUser(Login user) {
		 getSessionFactory().getCurrentSession().update(user);

	}

	

}
